package configuration.instructions;

import layers.agents.PackageAgent;
import layers.physical.Crossroad;
import layers.physical.Package;
import events.packageEvents.PackageCreatedEvent;
import framework.events.EventBroker;
import framework.instructions.creation.CreateInstruction;

public class CreatePackageInstruction extends CreateInstruction {

	private Crossroad origin;
	private Crossroad destination;
	private int id;

	public CreatePackageInstruction(long executionTime, int objectId, Crossroad origin, Crossroad destination) {
		super(executionTime, objectId);
		this.origin = origin;
		this.destination = destination;
		this.id = objectId;
	}
	
	@Override
	protected Object createObject() {
		Package pack = new Package(id, origin, destination);
		PackageAgent agent = new PackageAgent(pack);
		origin.recievePackage(agent);
		EventBroker.getEventBroker().notifyAll(new PackageCreatedEvent(pack.getId(), agent, origin.getPosition(), this.origin));
		return pack;
	}
}





